package com.project.service.proxy;

import com.project.baseInfo.dto.UserDto;
import com.project.baseInfo.model.Result;
import com.project.baseInfo.model.User;
import com.project.baseInfo.vo.UserVo;
import com.project.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 静态代理模式举例，registerUser添加打印日志功能
 */
@Service("userServiceImplProxy")
public class UserServiceImplProxy implements UserService {

    // 目标对象
    @Autowired // 通过注解传入目标对象
    @Qualifier("userServiceImpl") // 或者用spring的bean id配置
    private UserService userService;

    @Override
    public User getUserById(Long id) {
        return userService.getUserById(id);
    }

    @Override
    public User getUserByUserName(String userName, Integer delFlg) {
        return userService.getUserByUserName(userName, delFlg);
    }

    @Override
    public Result<String> registerUser(UserDto user) {
        // 添加打印日志功能
        System.out.println("registerUser start!");
        Result<String> result = userService.registerUser(user);
        System.out.println("registerUser end!");
        return result;
    }

    @Override
    public Result<List<UserVo>> queryUserPage(UserDto user) {
        return userService.queryUserPage(user);
    }

    @Override
    public Result<String> deleteUserByIdList(UserDto userDto) {
        return userService.deleteUserByIdList(userDto);
    }

    @Override
    public Result<String> updateUser(UserDto userDto) {
        return userService.updateUser(userDto);
    }
}
